﻿namespace GlobalStringFormatter
{
    /// <summary>
    /// A predicate-format delegate pair. Each Formatter
    /// will be checked in turn to see if the predicate
    /// is true. If so, the corresponding format delegate 
    /// will be called.
    /// </summary>
    /// <typeparam name="TType"></typeparam>
    public class Formatter<TType>
    {
        #region Delegates

        /// <summary>
        /// Delegate which returns a boolean depending on some test of the value.
        /// </summary>
        /// <param name="value">The value being tested.</param>
        /// <returns>A boolean to indicate whether to use the corresponding Format function.</returns>
        public delegate bool Predicate(TType value);

        /// <summary>
        /// Delegate which returns the formatted string output.
        /// </summary>
        /// <param name="value">The value to be used in the formatted string.</param>
        /// <returns>The formatted string.</returns>
        public delegate string Format(TType value);

        #endregion

        #region Properties

        /// <summary>
        /// Delegate returns true for a given condition on the raw value.
        /// </summary>
        public Predicate PredicateFunction { get; private set; }

        /// <summary>
        /// Delegate returns a formatted string based on the raw value.
        /// </summary>
        public Format FormatFunction { get; private set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Default constructor takes a predicate and a format delegate.
        /// </summary>
        /// <param name="predicate">Returns true for a given condition on the raw value.</param>
        /// <param name="format">Returns a formatted string based on the raw value.</param>
        public Formatter(Predicate predicate, Format format)
        {
            PredicateFunction = predicate;
            FormatFunction = format;
        }

        #endregion
    }
}
